#include "kdcvideometadata.h"

#include "kdclib.h"

KDCVideoMetaData::KDCVideoMetaData(	const QString& aDemuxer, const QString& aCodec, int aWidth, int aHeight, int aBitrate, double aFps, int aLength, double aAspectRatio ) : pBitrate( aBitrate ), pFps( aFps ), pWidth( aWidth ), pHeight( aHeight ), pLength( aLength ), pAspectRatio( aAspectRatio ) 
{
	pFrameCount = qRound( pFps*pLength );

	if ( aCodec == "0x10000002" )
		pCodec = KDC::MPEG2;
	else
		if ( aCodec == "0x10000001" )
			pCodec = KDC::MPEG1;
	else
		pCodec == KDC::OtherVideoCodec;

	if ( aDemuxer == "mpegps" )
		pDemuxer = KDC::MPEGPS;
	else
		pDemuxer = KDC::OtherDemuxer;
}

int KDCVideoMetaData::frameCount() const
{
	return pFrameCount;
}

KDC::Demuxer KDCVideoMetaData::demuxer() const
{
	return pDemuxer;
}

KDC::VideoCodec KDCVideoMetaData::codec() const
{
	return pCodec;
}

double KDCVideoMetaData::aspectRatio() const
{
	return pAspectRatio;
}

int KDCVideoMetaData::width() const
{
	return pWidth;
}

int KDCVideoMetaData::height() const
{
	return pHeight;
}

int KDCVideoMetaData::bitrate() const
{
	return pBitrate;
}

double KDCVideoMetaData::fps() const
{
	return pFps;
}

int KDCVideoMetaData::length() const
{
	return pLength;
}

bool KDCVideoMetaData::isSVCDPALVideo() const
{
	if ( demuxer() == KDC::MPEGPS && fps() == 25.0 && width() == 480 && height() == 576 && codec() == KDC::MPEG2 && bitrate() <= 2600 )
		return TRUE;
	else
		return FALSE;
}

bool KDCVideoMetaData::isSVCDNTSCVideo() const
{
	if ( demuxer() == KDC::MPEGPS && fps() == 29.97 && width() == 480 && height() == 480 && codec() == KDC::MPEG2 && bitrate() <= 2600 )
		return TRUE;
	else
		return FALSE;
}

bool KDCVideoMetaData::isVCDPALVideo() const
{
	if ( demuxer() == KDC::MPEGPS && fps() == 25.0 && width() == 352 && height() == 288 && codec() == KDC::MPEG1 && bitrate() == 1152 )
		return TRUE;
	else
		return FALSE;
}

bool KDCVideoMetaData::isVCDNTSCVideo() const
{
	if ( demuxer() == KDC::MPEGPS && ( fps() == 29.97 || fps() == 23.976 ) && width() == 352 && height() == 240 && codec() == KDC::MPEG1 && bitrate() == 1152 )
		return TRUE;
	else
		return FALSE;
}

bool KDCVideoMetaData::isDVDPALVideo() const
{
	if ( demuxer() == KDC::MPEGPS && fps() == 25.0 && isPALDVDResolution( width(), height() ) && ( ( codec() == KDC::MPEG2 && bitrate() <= 9800 ) || ( codec() == KDC::MPEG1 && bitrate() <= 1856 ) ) )
		return TRUE;
	else
		return FALSE;
}

bool KDCVideoMetaData::isDVDNTSCVideo() const
{
	if ( demuxer() == KDC::MPEGPS && ( fps() == 29.97 || fps() == 23.976 ) && isNTSCDVDResolution( width(), height() ) && ( ( codec() == KDC::MPEG2 && bitrate() <= 9800 ) || ( codec() == KDC::MPEG1 && bitrate() <= 1856 ) ) )
		return TRUE;
	else
		return FALSE;
}

bool KDCVideoMetaData::isCVDPALVideo() const
{
	if ( demuxer() == KDC::MPEGPS && fps() == 25.0 && width() == 352 && height() == 576 && codec() == KDC::MPEG2 && bitrate() <= 2600 )
		return TRUE;
	else
		return FALSE;
}

bool KDCVideoMetaData::isCVDNTSCVideo() const
{
	if ( demuxer() == KDC::MPEGPS && fps() == 29.97 && width() == 352 && height() == 480 && codec() == KDC::MPEG2 && bitrate() <= 2600 )
		return TRUE;
	else
		return FALSE;
}
